/*
 *  ResetedSliderModule.h
 *  LID Library
 *
 *  Created by Alexander Trutchenko on 09/11/11.
 *  Copyright 2011 League of Independent Developers. All rights reserved.
 *
 */

#ifndef __CE_ResetedSliderModule_h__
#define __CE_ResetedSliderModule_h__

#include "cocos2dx_extentions/controls/CESliderDelegate.h"
#include "cocos2dx_extentions/controls/CESlider.h"

#include "cocos2d.h"



namespace cocosext {

#define CE_SLIDE_MODULE_MIN_VALUE	"_slide_module_min_val"
#define CE_SLIDE_MODULE_MAX_VALUE	"_slide_module_max_val"
#define CE_SLIDE_MODULE_VALUE		"_slide_module_val"
#define CE_SLIDE_MODULE_RESET_VALUE "_slide_module_reset_val"

/////////////////////////////////////////////////////
//
/** CEResetedSliderModule 
* 
*/
/////////////////////////////////////////////////////

class CEResetedSliderModule : public cocos2d::CCNode, public CESliderDelegate, public CESliderInterface
{
typedef std::list<CESliderDelegate*> CESliderDelegates; 

protected:
	int _sliderTag;
	cocos2d::CCMenu* _menu;
	CESlider* _slider;
	float _minValue;
	float _maxValue;
	float _resetValue;
	std::string _sliderKey;
    CESliderDelegates _realDelegates; //weak refs
	cocos2d::CCLabelTTF* _lbName;
	cocos2d::CCLabelTTF* _lbMinValue;
	cocos2d::CCLabelTTF* _lbMaxValue;
	cocos2d::CCLabelTTF* _lbValue;
	cocos2d::CCLabelTTF* _lbResetValue;

protected:
	CEResetedSliderModule(const char* sliderKey)
		: _sliderTag(0)
		, _menu(NULL)
		, _slider(NULL)
		, _minValue(0.f)
		, _maxValue(1.f)
		, _resetValue(1.f)
		, _sliderKey(sliderKey)
		, _lbName(NULL)
		, _lbMinValue(NULL)
		, _lbMaxValue(NULL)
		, _lbValue(NULL)
		, _lbResetValue(NULL)	
	{
		this->setIsRelativeAnchorPoint(true);
	}

    virtual bool init(cocos2d::CCSprite* backNormal, 
						cocos2d::CCSprite* backDisabled, 
						cocos2d::CCSprite* btnNormal, 
						cocos2d::CCSprite* btnDisabled, 
						float sliderMargin, 
						float anyInitValue);

public:
    virtual ~CEResetedSliderModule() {;}

	    /* Static constructor */
    static CEResetedSliderModule* node( cocos2d::CCSprite* backNormal, 
										cocos2d::CCSprite* backDisabled, 
										cocos2d::CCSprite* btnNormal, 
										cocos2d::CCSprite* btnDisabled, 
										float sliderMargin, 
										const char* sliderKey,
										float anyInitValue = 0.5f);

public:

// CESliderInterface
    /* Get/set slider value */
    virtual float getValue() const;
    virtual void setValue(float value);

    /* Enable/disable slider */
    virtual void setIsEnabled(bool enabled);
    virtual bool isEnabled() const;

    /* Register/unregister delegates */
    virtual void registerDelegate(CESliderDelegate* delegate, bool synchronize);
    virtual void unregisterDelegate(CESliderDelegate* delegate);

	/* Get/set slider tag */
	virtual int getSliderTag() const { return _sliderTag; }
	virtual void setSliderTag(int sliderTag) { _sliderTag = sliderTag; }

public:
        /* Callbacks from slider */
    virtual void onValueChange(CESliderInterface* slider);
    virtual void onSlideBegin(CESliderInterface* slider);
    virtual void onSlideEnd(CESliderInterface* slider);
    virtual void onSlideCancelled(CESliderInterface* slider);

private:
	void onIncreaseResetValue(cocos2d::CCObject* caller);
	void onDecreaseResetValue(cocos2d::CCObject* caller);
	void onReset(cocos2d::CCObject* caller);
};


}; // end namespace cocosext

#endif // __CE_ResetedSliderModule_h__
